package com.cwnu.onlinemall.controller;

import com.cwnu.onlinemall.pojo.MallStaff;
import com.cwnu.onlinemall.pojo.ServerResult;
import com.cwnu.onlinemall.service.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin
public class StaffController {
    @Autowired
    StaffService staffService;


    @RequestMapping("/mallStaff/selectAll")
    public ServerResult selectAll(){
        List<MallStaff> mallStaffList = staffService.selectAll();
        return new ServerResult(0,"查询成功",mallStaffList);
    }

    @RequestMapping("/mallStaff/insert")
    public ServerResult insert(MallStaff mallStaff){
        Integer insertRow = staffService.insert(mallStaff);
        if(insertRow>=1){
            return new ServerResult(0,"添加成功",null);
        }else{
            return new ServerResult(1,"添加失败",null);
        }
    }

    @RequestMapping("/mallStaff/deleteBById")
    public ServerResult deleteById(Integer id){
        Integer deleteRow = staffService.deleteById(id);
        if(deleteRow>=1){
            return new ServerResult(0,"删除成功",null);
        }else{
            return new ServerResult(1,"删除失败",null);
        }
    }

    @RequestMapping("/mallStaff/selectById")
    public ServerResult selectById(Integer id){
        MallStaff mallStaff=staffService.selectById(id);
        return new ServerResult(0,"查询成功",mallStaff);
    }

    @RequestMapping("/mallStaff/updateById")
    public ServerResult updateById(MallStaff mallStaff){
        Integer updateRow = staffService.updateById(mallStaff);
        if(updateRow>=1){
            return new ServerResult(0,"修改成功",null);
        }else{
            return new ServerResult(1,"修改失败",null);
        }
    }
}
